﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.baidu.ai;

public partial class User_Face_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = "<span style='color: #c2c2c2; font-size: x-small'>**请保持环境光线充足以提高刷脸登录准确度！**<br />**准备好后点击下方按钮即可登录！**</ span > ";
    }

    protected void capture_Click(object sender, EventArgs e)
    {
        string name = Session["UserName"].ToString();
        string tel = Session["UserTel"].ToString();
        string password = Session["UserPass"].ToString();
        string email = Session["UserMail"].ToString();

        string PreBase64 = HiddenField1.Value;
        string Base64 = "";
        if (PreBase64.Contains("data:image/png;base64,"))
        {
            Base64 = PreBase64.Replace("data:image/png;base64,", "");
        }
        if (PreBase64.Contains("data:image/jpg; base64,"))
        {
            Base64 = PreBase64.Replace("data:image/jpg;base64,", "");
        }
        if (PreBase64.Contains("data:image/jpeg; base64,"))
        {
            Base64 = PreBase64.Replace("data:image/jpeg;base64,", "");
        }
        //PreBase64.Replace("data:image/png;base64,", "");
        //Response.Write(Base64);
        string Access_Token = AccessToken.getAccessToken();
        string feedback = FaceSearch.Search(Access_Token, Base64);
        string backid = ReturnResultDetect.GetFaceSearchReturnResult(feedback);
        if (backid=="_0")
        {
            Label1.Text = "<span style='color: #f00; font-size: smaller'>**未检测到人脸，请重试！**</span> ";
        }
        else if (backid == "_1")
        {
            Label1.Text = "<span style='color: #f00; font-size: smaller'>**您尚未注册，请注册后登录**</span> ";
            Response.Redirect("Faca_Login_error.aspx");
        }
        else
        {
            Session["Move_Name"] = backid;
            Session["Move_Islogin"] = 2;
            Response.Redirect("Move_User.aspx");
        }
        //Response.Write(backid);
        //string Face_Add_Return = FaceAdd.add(Access_Token, Base64, tel);
        //Response.Write(Face_Add_Return);
        //int Face_Add_Result = ReturnResultDetect.GetFaceAddReturnResult(Face_Add_Return);
        //Response.Write(Face_Add_Result);
        //if (Face_Add_Result == 1)
        //{

        //}
        //else
        //{
        //    Label1.Text = "<span style='color: #f00; font-size: smaller'>**未检测到人脸，请重试！**</span> ";
        //}



    }
}